package com.wqiuqiu.gulimall.order.listener;


import com.rabbitmq.client.Channel;
import com.wqiuqiu.gulimall.order.service.OrderService;
import com.wqiuqiu.gulimall.order.vo.SubmitResponseVo;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.amqp.core.Message;

import java.io.IOException;

@Component
public class OrderListenr {

    @Autowired
    OrderService orderService;


    @RabbitListener(queues = "order.release.order.queue")
    public void listener(String orderSn, Channel channel, Message message) throws IOException {
        System.out.println("收到过期订单消息：准备关闭订单" + orderSn);
        try {
            orderService.releaseOrder(orderSn);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
        }
    }
}
